/***************************************************************
*
*  Synopsis:    x509 certficate management
*    	    
*  Description:
*     	    
*  History:
*      	         dietrich - Jan 18, 2012:  Created.
*
***************************************************************/

/* $Id: x509.h,v 1.1 2012/01/18 08:20:34 dietrich Exp $ */

#ifndef _X509_H__
#define _X509_H__


/*  Type definitions */
typedef enum {
	rsa,
	dh
} algorithmIdentifier;

typedef enum {
	md5WithRsaEncryption,
	sha1WithRsaEncryption
} signatureAlgorithIdentifier;

/* Distinguished name */
typedef struct {
	char * idAtCountryName;
	char * idAtStateOfProvinceName;
	char * idAtLocalityName;
	char * idAtOrganizationName;
	char * idAtOrganizationalUnitName;
	char * idAtCommonName;
} name;

typedef struct {
	time_t notBefore;
	time_t notAfter; 
} validity_period;

typedef  mpz_t  uniqueIdentifier;

typedef struct {
	algorithmIdentifier algorithm;
	rsa_key_t rsa_public_key; 
} public_key_info;

typedef mpz_t objectIdentifier;

typedef struct {
	int version;
	mpz_t serialNumber;
	signatureAlgorithIdentifier signature;
	name issuer;
	public_key_info subjectPublicKeyInfo;
	uniqueIdentifier issuerUniqueId;
	uniqueIdentifier subjectUniqueId;
	int certificate_authority; // 1 this is a CA,  0 if not
	validity_period validity;
	name subject;
} x509_certficate;

typedef struct
{
	x509_certficate tbsCertificate;
	signatureAlgorithIdentifier algorithm;
	mpz_t signature_value;

	int hash_len;
	int *hash;
} signed_x509_certficate;


#endif /* X509 */
